define(function (require,exports,module) {
    var myPub = require('./public');
    var oGiftAddresBtn = $('.js_giftAddresBtn');                    // 提交按钮
    var oAddrBoxShow = $('.js_addrBoxShow');                        // 显示地址区域
    var submitTap = true;                                           // 提交按钮防多次点击
    var address_timer = null;                                       // 提交按钮定时器
    var dataJson = JSON.parse(addressList);
    var submitUrl = '/shop/gift/saveChooseAddressGiftOrder';

    // 手机号码隐藏
    oAddrBoxShow.on('click',function (e) {
        var oShowNum = '';
        var oPhoneNum = '';
        var oHidePhoneNUm = '';
        var target = e.target;
        if($(target).hasClass('js_showNum')){
            oShowNum = $(target);
            oPhoneNum = oShowNum.siblings('a').find('.js_phoneNum');
            oHidePhoneNUm = oShowNum.siblings('a').find('.js_hidePhoneNUm');
        }else{
            return
        }
        var nPhoneNum = oPhoneNum.text();
        var nHideNum = nPhoneNum.substr(0,3)+'****'+nPhoneNum.substr(7,11);
        oHidePhoneNUm.text(nHideNum);
        if(oShowNum.hasClass('on')){
            oPhoneNum.hide();
            oHidePhoneNUm.show();
            oShowNum.removeClass('on icon-eye_look').addClass('icon-eye_close')
        }else{
            oHidePhoneNUm.hide();
            oPhoneNum.show();
            oShowNum.addClass('on icon-eye_look').removeClass('icon-eye_close')
        }
    });


    oGiftAddresBtn.on('click',function () {
        if(!submitTap)return;
        submitTap = false;
        G_JSON_POST(submitUrl,{'encryptStr':encryptStr},function (data) {
            if(data.return_code == 'FAIL'){
                myPub.TipLayerEnd(data.return_msg,'no')
            }else if(data.return_code == 'SUCCESS'){
                myPub.TipLayerEnd(data.return_msg,'no',function () {
                    window.location.href = '/shop/pay/order_list'
                },2)
            }
        });
        clearTimeout(address_timer);
        address_timer = setTimeout(function () {
            submitTap = true
        },250)
    });

    var addressAdd = {
        addressHtml:function () {
            var _this = this;
            var thtml = '';
            if(addressCount && addressCount.length > 0){
                // console.log(dataJson);
                for(var i = 0;i<addressCount*1;i++){
                    if(dataJson[i+1]){
                        // console.log('有'+(i+1));
                        var mobilHtml = dataJson[i+1].mobile.substr(0,3)+'****'+dataJson[i+1].mobile.substr(7,11);
                        thtml +=
                            '<div class="addrBox active HBox BoxCenter js_userAddr">'+
                            '   <div class="iconStyle icon_addrLoc"></div>'+
                            '   <div class="Bflex1  seletAddr js_seletAddr encrypt">'+
                            '       <a href="'+BASE+'/member/address/chooseAddress?encryptStr='+encryptStr+'&index='+(i+1)+'">'+
                            '           <p class="indexAddr clearfix">'+
                            '               <span> '+dataJson[i+1].fullName+'</span>'+
                            '               <span class="fr">'+
                            '               <em class="js_phoneNum showPhoneNum" style="display: none">'+dataJson[i+1].mobile+'</em>'+
                            '               <em class="js_hidePhoneNUm showPhoneNum">'+mobilHtml+'</em>'+
                            '               </span>'+
                            '           </p>'+
                            '           <p class="addrDetail">'+
                            '               <span class="addrTit" id="province">'+dataJson[i+1].province+'</span>'+
                            '               <span>'+dataJson[i+1].city+'</span>'+
                            '               <span>'+dataJson[i+1].area+'</span>'+
                            '               <span>'+dataJson[i+1].address+'</span>'+
                            '           </p>'+
                            '       </a>'+
                            '       <em class="iconStyle icon-eye_close js_showNum eyeAddress encryptEye"></em>'+
                            '   </div>'+
                            '   <i class="iconStyle icon-href-right iconArrow texRi"></i>'+
                            '</div>';
                    }else{
                        // console.log('无'+(i+1));
                        thtml +=
                            '<div class="addrBox active HBox BoxCenter js_userAddr">'+
                            '   <div class="iconStyle icon_addrLoc"></div>'+
                            '   <div class="Bflex1  seletAddr js_seletAddr">'+
                            '       <a href="'+BASE+'/member/address/chooseAddress?encryptStr='+encryptStr+'&index='+(i+1)+'">'+
                            '           <p><span class="addrTit">请选择收货地址</span></p>'+
                            '       </a>'+
                            '   </div>'+
                            '   <i class="iconStyle icon-href-right iconArrow texRi"></i>'+
                            '</div>';
                    }

                }
            }
            oAddrBoxShow.append(thtml)
        }

    };
    addressAdd.addressHtml();


});